<?php

use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration;

class CreateHscoinBillTable extends Migration
{
    public function up()
    {
        Schema::create('hscoin_bill', function (Blueprint $table) {
            $table->unsignedInteger('id')->autoIncrement()->comment('奖池id');
            $table->unsignedBigInteger('uid')->notNull()->default(0)->comment('用户uid');
            $table->tinyInteger('category')->notNull()->default(0)->comment('分类：可以关联对应表和id做支撑');
            $table->unsignedBigInteger('link_id')->notNull()->default(0)->comment('关联表主键id');
            $table->decimal('link_amount', 12, 2)->unsigned()->notNull()->default(0.00)->comment('金额: 容量100亿');
            $table->decimal('amount', 12, 2)->unsigned()->notNull()->default(0.00)->comment('金额: 容量100亿');
            $table->decimal('balance', 16, 2)->notNull()->default(0.00)->comment('余额');
            $table->decimal('user_balance', 16, 2)->unsigned()->notNull()->default(0.00)->comment('当前分类统计：分类不确定性，同步到eb_fund对应字段json,不能当文本操作');
            $table->string('mark', 255)->collation('utf8mb4_unicode_ci')->notNull()->default('')->comment('备注');
            $table->unsignedInteger('add_time')->notNull()->default(0)->comment('添加时间');
            $table->tinyInteger('status')->notNull()->default(1)->comment('1 = 有效 \r\n-1 = 取消：场景，比如退货\r\n-20= 取消对冲：场景取消时候系统新对冲记录\r\n-30=从取消状态恢复为有效状态对冲');
            $table->unsignedInteger('pid')->notNull()->default(0)->comment('上一条id');
            $table->index('uid');
            $table->index(['category', 'link_id', 'status'], 'link');
        });
    }

    public function down(Schema $schema)
    {
        Schema::dropIfExists('hscoin_bill');
    }
}